<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input
      @keyup.enter="add"
      v-model.trim="name"
      placeholder="请输入任务"
      class="new-todo"
    />
    <button class="add" @click="add">添加任务</button>
  </header>
</template>

<script>
export default {
  data() {
    return {
      name: "",
    };
  },
  methods: {
    add() {
      if (!this.name) {
        alert("请输入任务名称");
        return;
      }
      this.$emit("add", this.name);
      this.name = "";
    },
  },
};
</script>

<style>
</style>